#ifndef _VC10EA_

#include "AudioCompression.h"
#include "gvar.h"
#include "capTypes.h"
#include "../../Capture/CapLib.h"
#include "gsm.h"
#include "../../Echo/ec_sbx.h"	// echo cancelation

int		size_audio = 0;
int		AUDIO_SAMPLES = 160;
gsm				GSM_Encoder=0;
WAVEFORMATEX	AudioFormat;

#else //ndef _VC10EA_

int		size_audio;
int		AUDIO_SAMPLES;
gsm				GSM_Encoder;

#endif //ndef _VC10EA_

short	audio_data[160];
BYTE	packet[33*100];



short PrevAudio[160];
LRESULT AudioCompressCallback(HWND hWnd, BYTE *lpBufPtr, DWORD dwBufSize) 
{ 

	BYTE*	d=lpBufPtr;//(BYTE*)lpWHdr->lpData;
	int		size=dwBufSize;//lpWHdr->dwBytesRecorded;
	BYTE*	p=packet;
	int		out_size=0;

    if (!hWnd  || !cap_process || !CaptureEnable || !CaptureEnableAudio) 
        return FALSE;  

	size_audio=0;

	// echo cancel 
	if (0)
	{
		int isize=size>>1;
		short* sig=(short*) d;
		while (isize<160) {
			short pa[160];
			memcpy(pa,sig,320);
			EchoCancelProcessGSM(PrevAudio,sig);
			sig+=160; isize-=160;
			memcpy(PrevAudio,pa,320);
		}
	}


	while (size) {
	//size_audio=lpWHdr->dwBytesRecorded;
		if (GSM_Encoder) gsm_encode(GSM_Encoder, (gsm_signal*)d, (gsm_byte*)p);
		p+=33;
		size_audio += 33;
		out_size+=33;
		size-=320;
		d+=320;
	}

#ifndef _VC10EA_
	if (cap_process && out_size) cap_process(packet,out_size,FALSE);
#else //ndef _VC10EA_
	if(out_size) Process(packet, out_size, FALSE);
#endif //ndef _VC10EA_

    return (LRESULT) TRUE; 
} 

char AUDIO_EMPTY[320];
char AUDIO_SILENSE[33];
int AudioCompression_Create()
{

	GSM_Encoder=gsm_create();
	gsm_encode(GSM_Encoder, (gsm_signal*)AUDIO_EMPTY, (gsm_byte*)AUDIO_SILENSE);
	return 1;
}

int AudioCompression_Destroy()
{
	//	Close Audio codec
	if (GSM_Encoder) gsm_destroy(GSM_Encoder);
	GSM_Encoder=0;
	return 1;

}
